package ljt.music.module.tab3;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;

import com.ljq.mvpframework.presenter.BaseMvpPresenter;

import ljt.music.bean.UserList;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author jiangtao
 * @date 2017/12/21
 */

public class Tab3FragmentPresenter extends BaseMvpPresenter<Tab3FragmentView> {
  private Tab3FragmentModel mTab3FragmentModel;

  public Tab3FragmentPresenter() {
    this.mTab3FragmentModel = new Tab3FragmentModel();
  }

  public void request(String uid, String types) {
    Log.e("perfect-mvp", "点击事件 P ");
    if (getMvpView() != null) {
      getMvpView().requestLoading();
    }

    mTab3FragmentModel.request(uid, types, new Callback<UserList>() {
      @Override
      public void onResponse(Call<UserList> call, Response<UserList> response) {
        if (response.isSuccessful()) {
          getMvpView().resultSuccess(response.body());
        }
      }

      @Override
      public void onFailure(Call<UserList> call, Throwable t) {
        Log.i("TAG", t.toString());
      }
    });
  }

  @Override
  public void onCreatePresenter(@Nullable Bundle savedState) {
    super.onCreatePresenter(savedState);
    if (savedState != null) {
      Log.e("perfect-mvp", "MainActivityPresenter  onCreatePresenter 测试  = " + savedState.getString("test2"));
    }
  }

  @Override
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Log.e("perfect-mvp", "MainActivityPresenter  onSaveInstanceState 测试 ");
    outState.putString("test2", "test_save2");
  }

  @Override
  public void onDestroyPresenter() {
    super.onDestroyPresenter();
  }

  public void interruptHttp() {
    mTab3FragmentModel.interruptHttp();
  }
}
